import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ExecutorService;

public class Pool {

    public static void main(String[] args) {
        System.out.println("ThreadPool.");

        // ExecutorService es = Executors.newFixedThreadPool(2);

        // for(int i=0 ; i<=4 ; i++){
        //     es.submit(new TaskQ("" + i ));
        // }
        // es.shutdown();


        ScheduledExecutorService ses = Executors.newScheduledThreadPool(4);
        // once
        //ses.schedule(new TaskQ("one-time"), 1, TimeUnit.SECONDS);
        
        // 1s exec at fixed rate , no matter task is over
        //ses.scheduleAtFixedRate(new TaskQ("fixed-rate"), 1,2, TimeUnit.SECONDS);

        // 1s exec very 3 ,and the task is over
        ses.scheduleWithFixedDelay(new TaskQ("fixed-delay-"), 1, 3, TimeUnit.SECONDS);    


    }
}



class TaskQ implements Runnable {
    private final String tname;

    public TaskQ(String name){
        this.tname = name;
    }

    @Override
    public void run(){
        double num = Math.floor(Math.random()*100);
        System.out.println("run in " + this.tname + String.valueOf(num));
    }
}




